﻿<div class="ph-tabs">
    <ul>
        <li class="k-state-active">公告列表</li>
    </ul>
    <div>
        <div class="k-block divToolbar">
            <button class="k-button" onclick="CreateNew()"><span class="k-icon k-i-plus"></span><span>添加新公告</span></button>
        </div>
        <div id="grid_notice" style="text-align: center"></div>
    </div>
</div>

<script class="init">
    LocatedMenu("系统管理", "公告消息");
</script>

<script class="grid_columns">
    var fields = [{
        title: "标题",
        field: "Title",
        width: 500,
        attributes: { style: "text-align:left" }
    }, {
        title: "过期时间",
        field: "Expired",
        template: "#=kendo.toString(kendo.parseDate(Expired),'yyyy-MM-dd')#",
        width: 100
    }, {
        title: "添加时间",
        field: "CreatedOn",
        template: "#=kendo.toString(kendo.parseDate(CreatedOn),'yyyy-MM-dd')#",
        width: 100
    }, {
        title: "操作",
        template: "#=GetOperations(ID)#",
        width: 200,
        attributes: { style: "text-align:left" }
    }, {}];

    function GetOperations(id) {
        var html = "<button class='k-button' onclick=\"Edit(" + id + ")\"><span class='k-icon k-i-pencil'></span><span>修改</span></button>";
        html += "<button class='k-button' onclick=\"Delete(" + id + ")\"><span class='k-icon k-i-cancel'></span><span>删除</span></button>";
        return html;
    }

    function Edit(id) {
        if (wndGeneralEdit != null && typeof wndGeneralEdit != "undefined") {
            wndGeneralEdit.setOptions({ title: "修改公告信息", width: 700 });
            wndGeneralEdit.refresh({ url: "/Systems/Notice/Edit/" + id });
            wndGeneralEdit.open();
        }
    }

    function Delete(id) {
        if (confirm("真的要删除这个公告吗？")) {
            Whale.Remote.Operation({
                url: "/Systems/Notice/Delete",
                parameters: { id: id },
                success: function (result) {
                    if ($("#grid_notice").length > 0)
                        $("#grid_notice").data("kendoGrid").dataSource.read();
                },
                error: function (msg) {
                    wndGeneralInformation.content(msg).open();
                }
            });
        }
    }

    function CreateNew() {
        wndGeneralEdit.setOptions({ title: "添加新的公告", width: 700 });
        wndGeneralEdit.refresh({ url: "/Systems/Notice/Edit" });
        wndGeneralEdit.open();
    }
</script>

<script class="grid_config">
    $(function () {
        $("#grid_notice").kendoGrid({
            columns: fields,
            dataSource: Whale.dataSource({
                url: "/Systems/Notice/Gets",
                getParameters: function () {
                    return {

                    };
                },
                pageSize: 20
            }),
            pageable: {
                messages: {
                    empty: "暂无数据"
                }
            },
            dataBound: function (e) {
                //让表头居中
                $("th.k-header").attr("style", "text-align:center; font-weight:bold;");
            }
        });
    });
</script>
